package exercise;

import utils.JDBCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class Exercise {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入：");
        String name = scanner.nextLine();
        System.out.println("请输入邮箱：");
        String email = scanner.nextLine();
        System.out.println("请输入生日：");
        String birth = scanner.nextLine();

        String sql = "INSERT INTO customers(cust_id, cust_name, email, birth, photo) VALUES (NULL, ?,?,?,null)";
        int i = insertRecord(sql, name, email, birth);
        System.out.println(i);

    }

    public static  int insertRecord(String sql,  String... args){
        Connection connection = JDBCUtils.getConnection();
        int count = 0;
        try {
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            for (int i = 0; i < args.length; i++) {
                preparedStatement.setString(i + 1, args[i]);
            }

            count =  preparedStatement.executeUpdate();

        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }


        JDBCUtils.closeConnection();
        return count;
    }
}
